package com.tlvip;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * <p>description：</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary：
 * 手动插入内存屏障
 * 在需要插入内存屏障的代码前，调用方法reflectGetUnsafe
 * </p>
 * <p>instructions： </p>
 * Date 2022/5/21</p>
 * Author mac
 *
 * @version 1.0
 */
public class UnsafeInstance {
    public static Unsafe reflectGetUnsafe() {
        try {
            Field field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            return (Unsafe) field.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
